/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}


/**
 * 验证qq号
 * @param str
 * @returns {boolean}
 */
export function validQQ(str) {
  let reg = /[1-9][0-9]{4,}/
  return reg.test(str)
}

/**
 * 验证手机号
 * @param str
 * @returns {boolean}
 */
export function validPhone(str) {
  let reg = /^1(3|4|5|6|7|8|9)\d{9}$/
  return reg.test(str)
}

/**
 * 验证邮箱
 * @param str
 * @returns {boolean}
 */
export function validEmail(str) {
  
  let reg = /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/
  return reg.test(str)
}

/**
 * 验证ip地址
 * @param str
 * @returns {boolean}
 */
export function validIP(str) {
  let reg = /(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d).(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d).(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d).(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)/
  return reg.test(str)
}

/**
 * 验证身份证
 * @param str
 * @returns {boolean}
 */
export function validID(str) {
  let reg = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/
  return reg.test(str)
}

/**
 * 验证URL
 * @param str
 * @returns {boolean}
 */
export function validURL(str) {
  let reg = /[a-zA-z]+:\/\/[^\s]*/
  return reg.test(str)
}

